// 导入本地存储 api
import { setStorage, clearStorage, getStorage } from '../../utils/storage'
import { getClassList, register } from '../../api/clazz'
Page({
  data: {
    userInfo: {},
    className: '',
    tokenFlag: false,
    userInfoFlag: false
  },
  onShow: function () {
    // 获取本地存储的信息
    const token = getStorage('token');
    const userInfo = getStorage('userInfo');
    let tokenFlag = false;
    if (token) {
      tokenFlag = true;
    }
    if (!userInfo || !tokenFlag) {
      this.setData({
        tokenFlag: false,
        userInfoFlag: false
      });
    } else { // 已登录后
      const className = getStorage('classInfo').className
      this.setData({
        userInfo,
        tokenFlag: true,
        userInfoFlag: true,
        className
      });
    }
  },
  // 跳转到登录页面
  toLoginPage() {
    wx.navigateTo({
      url: '/pages/login/login'
    })
  }
})